<?php
include_once 'cls_mysql.php';
class Type extends Mysql{
	public $table = '12_type';
	public function getTree($pid = 0,$typeTree = array(),$level = 0){
		$this-> where = array('pid'=>$pid);
		$list = $this->getList();
		//print_r($list);exit;
		foreach($list as $k){
			$levelStr = '<font color="red">';
			for($i=0;$i<$level;$i++){
				$levelStr.='|-';
			}
			$levelStr.='</font>';
			$k['name']=$levelStr.$k['name'];
			$typeTree[] = $k;
			$typeTree = $this->getTree($k['id'],$typeTree,$level+1);
		}
		
		return $typeTree;
		
	}
	public function getTreeTop($pid = 0){
		$this-> where = array('pid'=>$pid);
		$list = $this->getList();
		return $list;
	}
	
	//递归删除函数
	public function typeDelete($id){
		//$this->where = array('pid'=>$pid);
		//$list = $this->getList();//获取当前数据
		//$next = $this->getTree($id);
		//print_r($next);exit;
		$list = $this->getTreeTop($id);//获取下一级数据
		//print_r($list);exit;
		foreach($list as $n){
			$this->typeDelete($n['id']);
		}
		
		
		//print_r($w);exit;
		//echo "删除.".$id.'<br/>';
		
		//$pid =!empty($_GET['pid'])?$_GET['pid']:0;
		//$levelList = $db->getTreeTop($pid);
	}
}
?>